package com.yunsom.testdemo.design.watcher;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Xbao
 * @version 1.0
 * @description
 * @date 2021/3/22 20:01
 */
public class Subject {

  private List<AbstractObserver> abstractObservers = new ArrayList<AbstractObserver>();

  private int state;

  public int getState() {
    return state;
  }

  public void setState(int state) {
    this.state = state;
  }

  public void attach(AbstractObserver abstractObserver){
    abstractObservers.add(abstractObserver);
  }

  public void notifyAllObservers(){
    for (AbstractObserver abstractObserver : abstractObservers){
      abstractObserver.update();
    }
  }

}
